package logic

import (
	"context"
	"house-hub/models"

	"house-hub/houserpc/houserpc"
	"house-hub/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailLogic {
	return &DetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *DetailLogic) Detail(in *houserpc.DetailRequest) (*houserpc.DetailResponse, error) {
	// todo: add your logic here and delete this line

	var goods models.Goods
	if err := goods.DetailGoods(models.DB, in.GoodsId); err != nil {
		return nil, err
	}

	return &houserpc.DetailResponse{
		Title:  goods.Title,
		UserId: int64(goods.UserId),
		Price:  float32(goods.Price),
	}, nil
}
